﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Server.Model;

namespace Server.Data
{
    public class UserDAO : BaseDAO
    {
        /// <summary>
        /// return the generated ID
        /// </summary>
        /// <param name="pParent"></param>
        /// <param name="pUserID"></param>
        /// <param name="pUserName"></param>
        /// <returns></returns>
        public long CreateParent(ParentInfo pParent, long? pUserID, string pUserName)
        {
            return Convert.ToInt64(base.ExecuteScalar("sp_Insert_User_Parent", pParent.UserName, pParent.Password, pParent.Telephone
                , pParent.City, pParent.Province, pParent.Email, pUserID, pUserName).ToString());
        }

        public void UpdateParent(ParentInfo pParent, long pUserID, string pUserName)
        { 
            base.ExecuteNonQuery("sp_Update_User_Parent", pParent.UserName,pParent.Password, pParent.Telephone,
                pParent.City, pParent.Province, pParent.Email, pUserID, pUserName);
        }

        public void CreateClient(ClientInfo pClient, long pUserID, string pUserName)
        { 
            base.ExecuteNonQuery("sp_Insert_User_Client",
                pClient.ClientName, pClient.Password, pClient.IP, pUserID, pUserName);
        }

        public void UpdateClient(ClientInfo pClient, long pUserID, string pUserName)
        {
            base.ExecuteNonQuery("sp_Update_User_Client", 
                pClient.ID, pClient.ClientName, pClient.Password, pClient.IP, pClient.ParentID, pUserID, pUserName);
        }
    }
}
